package com.wct.springcloud.controller;

import com.wct.springcloud.model.Dept;
import com.wct.springcloud.service.DeptClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author WEI (Email:changtan20000@163.com)
 * @description
 * @date: 2019/12/11 21:01
 */
@Slf4j
@RestController
public class DeptConsumerController {

    @Autowired
    private DeptClientService deptClientService;

/*    @Autowired
    private RestTemplate restTemplate;
    private static String DEPT_URL = "http://localhost:8001";
    private static String DEPT_NAME = "http://MICROSERVICECLOUD-DEPT-PROVIDER";*/

    @RequestMapping("/consumer/dept/get/{deptno}")
    public Dept get(@PathVariable Integer deptno){
//        Dept dept = restTemplate.getForObject(DEPT_NAME+ "/dept/get/" + deptno, Dept.class);
        Dept dept = deptClientService.get(deptno);
        log.info("/consumer/dept/get/{} dept: {}", deptno, dept.toString());
        return dept;
    }

    @RequestMapping("/consumer/dept/list")
    public List<Dept> list(){
//        List<Dept> deptList = restTemplate.getForObject(DEPT_NAME+ "/dept/list", List.class);
        List<Dept> deptList = deptClientService.list();
        log.info("/consumer/dept/list {}", deptList.toString());
        return deptList;
    }
}
